package com.ruizhong.centercontroll.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruizhong.centercontroll.dao.TLanguageMapper;
import com.ruizhong.centercontroll.entity.TLanguage;
import com.ruizhong.centercontroll.service.TLanguageService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class TLanguageServiceImpl extends ServiceImpl<TLanguageMapper, TLanguage> implements TLanguageService {
    @Override
    public Boolean checkPassword(String pwd) {
        List<TLanguage> list =list();
        TLanguage tLanguage =list.get(0);
        if (StringUtils.isEmpty( tLanguage.getPassword())){
            return Boolean.TRUE;
        }
        return tLanguage.getPassword().equals(pwd);
    }

    @Override
    public String getPassword() {
        List<TLanguage> list =list();
        TLanguage tLanguage =list.get(0);
        return tLanguage.getPassword();
    }

    @Override
    public synchronized void submitNewPassword(String password) {
        List<TLanguage> list = list();
        TLanguage tLanguage = list.get(0);
        tLanguage.setPassword(password);
        updateById(tLanguage);
    }

    @Override
    public String getRandomId(HttpServletRequest request) {
        return UUID.randomUUID().toString();
    }

    @Override
    public void changeMinimizeOnStartup(Boolean mos) {
        List<TLanguage> list = list();
        TLanguage tLanguage = list.get(0);
        tLanguage.setMinimizeOnStartup(mos);
        updateById(tLanguage);
    }

    @Override
    public Map<String, Object> getSettings() {
        List<TLanguage> list = list();
        TLanguage tLanguage = list.get(0);
        HashMap<String, Object> settingMap = new HashMap<>();
        settingMap.put("MinimizeOnStartup",tLanguage.getMinimizeOnStartup());
        return settingMap;
    }
}
